<template>
    <el-card class="!border-none" shadow="never">
        <el-alert :closable="false" show-icon>
            <template #title>
                <div>设置社区团购平台的截单时间</div>
            </template>
        </el-alert>
    </el-card>
    <el-card class="!border-none mt-[15px]" shadow="never">
        <div class="font-medium mb-7">社区订单发货设置</div>
        <el-form ref="formRef" :model="formData" label-width="150px">
            <el-form-item
                label="系统截单时间"
                v-if="formData.deliver_time_type === 1 || formData.deliver_time_type === 2"
            >
                <div>
                    <el-time-select
                        v-model="formData.system_cutoff_time"
                        start="00:00"
                        step="00:15"
                        end="23:59"
                        placeholder="请选择"
                    />

                    <div class="form-tips" v-if="formData.deliver_time_type === 1">
                        在设定的时间内下单，都属于当日达，超过该时间下单，则为次日达
                    </div>
                    <div class="form-tips" v-if="formData.deliver_time_type === 2">
                        在设定的时间内下单，都属于次日达，超过该时间下单，则为隔日达
                    </div>
                </div>
            </el-form-item>
            <el-form-item label="提货时间">
                <div>
                    <el-time-select
                        v-model="formData.take_time"
                        start="00:00"
                        step="00:15"
                        end="23:59"
                        placeholder="请选择"
                    />
                    <div class="form-tips">用户提货时间</div>
                </div>
            </el-form-item>
            <el-form-item label="发货时间类型">
                <div>
                    <el-radio-group v-model="formData.deliver_time_type">
                        <el-radio :label="1">当日达</el-radio>
                        <el-radio :label="2">次日达</el-radio>
                        <el-radio :label="3">隔日达</el-radio>
                    </el-radio-group>
                </div>
            </el-form-item>
        </el-form>
    </el-card>
    <footer-btns>
        <el-button type="primary" @click="handleSubmit">保存</el-button>
    </footer-btns>
</template>
<script setup lang="ts">
import { setCutoff, getCutoff } from '@/api/setting/deal'
const formData = reactive({
    system_cutoff_time: '',
    take_time: '',
    deliver_time_type: 1
})
const handleSubmit = async () => {
    try {
        await setCutoff(formData)
        getData()
    } catch (error) {
        console.log('保存=>', error)
    }
}
const getData = async () => {
    try {
        const data = await getCutoff()
        for (const key in formData) {
            //@ts-ignore
            formData[key] = data[key]
        }
    } catch (error) {
        console.log('获取=>', error)
    }
}
getData()
</script>
<style scoped lang="scss">
.el-alert--info {
    color: rgba(64, 115, 250, 1);
    background-color: rgba(246, 248, 255, 1);
}
</style>
